package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-12 14:34
 */
public class Solution_1137 {
    /**
     * 第 N 个泰波那契数
     *
     * @param n
     * @return
     */
    public int tribonacci(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        if (n == 2) return 1;

        int[] res = new int[n + 1];
        res[0] = 0;
        res[1] = 1;
        res[2] = 1;
        for (int i = 3; i <= n; i++) {
            res[i] = res[i - 1] + res[i - 2] + res[i - 3];
        }
        return res[n];

    }
}
